import React from 'react';
import ReactDom from 'react-dom';
import {service} from './service/service';
import {inject} from "./utils";


@inject({service})
@observer
class Root extends React.Component {
    require_data(){
        this.props.service.require_homework(this);
    }

    draw_graph(week, data){
        this.myChart = echarts.init(document.getElementById('bar'));
        this.myChart.setOption(
            {
                title: {
                    text: '每周提交作业人数条形图'
                },
                tooltip: {},
                legend: {
                    data:['销量']
                },
                xAxis: {
                    data: week
                },
                yAxis: {},
                series: [{
                    name: '作业提交数',
                    type: 'bar',
                    data: data,
                }],
            }
        );
    }

    draw_pie(data){
        console.log(data);
        this.myChart = echarts.init(document.getElementById('pie'));
        this.myChart.setOption(
            {
                grid:{
                    height: '40%',
                    bottom: 50
                },
                title: {
                    text: '每周提交作业人数饼形图'
                },
                tooltip: {},
                legend: {
                    data:['销量']
                },
                series: [ {
                    name: "作业提交数",
                    type: 'pie',
                    data: data,
                    center: ["50%","50%"],
                    radius: [0,"50%"]
                }],
            }
        );
    }
    render() {
        this.require_data.bind(this)();
        return (
            <div></div>
        );
    }

}


ReactDom.render(<Root/>, document.getElementById('root'));


